package com.iuie.ns.datum.service.impl;

import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.iuie.ns.datum.mapper.MsgMapper;
import com.iuie.ns.datum.service.IMsgService;
import com.iuie.ns.datum.vo.PlatformMsgVO;
import com.iuie.ns.frame.utils.DateUtils;
import com.iuie.ns.frame.web.dataset.vo.Page;

@Service("msgService")
public class MsgServiceImpl implements IMsgService {
	
	@Resource
	private MsgMapper msgMapper;

	@Override
	public List<PlatformMsgVO> findLatestMsg(PlatformMsgVO platformMsg, Page page, String blogAttr) throws ParseException {
		PageHelper.startPage(page.getPage(), page.getRows(), true);
		
		final String DATE_FORMAT = "yyyy-MM-dd";
		if (platformMsg.getStartTime() == null) {
			platformMsg.setStartTime(DateUtils.strDateToPatternDate(DateUtils.getCurrTimeChangeNthDayDate(-6, DATE_FORMAT), DATE_FORMAT));
		}
		if (platformMsg.getEndTime() == null) {
			platformMsg.setEndTime(DateUtils.strDateToPatternDate(DateUtils.getCurrTimeChangeNthDayDate(1, DATE_FORMAT), DATE_FORMAT));
		}
		List<PlatformMsgVO> list = msgMapper.findLatestMsgFromBlog(platformMsg, blogAttr);
		page.loadData(list);
		return list;
	}

}
